package cn.livingCloud.dto;

import cn.livingCloud.entity.system.ImageResource;
import cn.livingCloud.entity.user.User;
import cn.livingCloud.utils.DateUtils;
import cn.livingCloud.utils.HtmlRegexpUtil;
import org.apache.commons.lang.StringUtils;

/**
 * Created by 唐旭 on 2016/2/15.
 */
public class ImageItemDto {
    private String uuid;
    //图片地址
    private String path;
    private String originalFileName;
    //创建时间
    private String createTime;
    //扩展名
    private String extName;
    //创建人
    private UserDto creater;

    private boolean archive;

    private String url;

    private String shortFileName;

    public ImageItemDto() {
    }

    public ImageItemDto(ImageResource resource) {
        this.uuid = resource.getUuid();
        this.path = resource.getPath();
        this.url = resource.getUrl();
        this.originalFileName = HtmlRegexpUtil.replaceTag(resource.getOriginalFileName());
        this.createTime = DateUtils.toDateText(resource.getCreateTime(), DateUtils.DEFAULT_DATE_TIME_FORMAT);
        this.extName = resource.getExtName();
        User creater = resource.getCreater();
        if (creater != null) {
            this.creater = new UserDto(resource.getCreater());
        }
        this.archive = resource.isArchive();
        if (StringUtils.isEmpty(originalFileName)) {
            originalFileName = "未找到图片";
        }
        if (originalFileName.length() > 20) {
            this.shortFileName = originalFileName.substring(0, 19) + "...";
        } else {
            this.shortFileName = originalFileName;
        }
    }

    public String getUuid() {
        return uuid;
    }

    public ImageItemDto setUuid(String uuid) {
        this.uuid = uuid;
        return this;
    }

    public String getPath() {
        return path;
    }

    public ImageItemDto setPath(String path) {
        this.path = path;
        return this;
    }

    public String getOriginalFileName() {
        return originalFileName;
    }

    public ImageItemDto setOriginalFileName(String originalFileName) {
        this.originalFileName = originalFileName;
        return this;
    }

    public String getCreateTime() {
        return createTime;
    }

    public ImageItemDto setCreateTime(String createTime) {
        this.createTime = createTime;
        return this;
    }

    public String getExtName() {
        return extName;
    }

    public ImageItemDto setExtName(String extName) {
        this.extName = extName;
        return this;
    }

    public UserDto getCreater() {
        return creater;
    }

    public ImageItemDto setCreater(UserDto creater) {
        this.creater = creater;
        return this;
    }

    public boolean isArchive() {
        return archive;
    }

    public ImageItemDto setArchive(boolean archive) {
        this.archive = archive;
        return this;
    }

    public String getUrl() {
        return url;
    }

    public ImageItemDto setUrl(String url) {
        this.url = url;
        return this;
    }

    public String getShortFileName() {
        return shortFileName;
    }

    public ImageItemDto setShortFileName(String shortFileName) {
        this.shortFileName = shortFileName;
        return this;
    }
}
